package com.bauer.separation.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import com.bauer.separation.common.Response;

@Aspect
@Component
public class ControllerException {

	@Pointcut("execution(* com.bauer.separation.action..*(..))")  
    private void anyMethod(){}//定义一个切入点 
	
	
	@Around("anyMethod()")  
    public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable{  
		Object object =null;
		Response<?> res= new Response<Object>();
		try{
			object= pjp.proceed();//执行该方法  
			if(object instanceof Response){
				res=(Response<?>) object;
			}
		}catch(Exception e){
			res.failure(false, "系统异常");
		}
        return res;  
    }
	
	@AfterThrowing(pointcut = "anyMethod()", throwing = "e")    
	public void handleException(JoinPoint joinPoint, Throwable e){
		
	}
	
	
}
